<template>
  <div class="padding" v-loading="loading">
    <el-card>
      <div slot="header" class="clearfix">
        <span>销售总业绩排行</span>
      </div>

      <el-form v-model="searchForm" size="mini" label-width="80px">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="入库时间" prop="rangeInStockMonth">
              <el-date-picker
                type="daterange"
                v-model="searchForm.rangeInStockMonth"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                :style="{ width: '100%' }"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                range-separator="至"
                clearable
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item prop="shippingWay">
              <div slot="label">渠道：</div>
              <el-select
                v-model="searchForm.shippingWay"
                filterable
                placeholder="默认选择全部"
              >
                <el-option
                  v-for="(item, value) in salePerformanceVo.channelWayMap"
                  :key="value"
                  :label="item"
                  :value="value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item prop="saleUserGroupIds">
              <div slot="label">部门：</div>
              <el-select
                v-model="searchForm.saleUserGroupId"
                filterable
                placeholder="默认选择全部"
              >
                <el-option
                  v-for="(item, value) in salePerformanceVo.saleGroupMap"
                  :key="value"
                  :label="item"
                  :value="value"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-button size="mini" type="primary" @click="statistics"
              >统计</el-button
            >
          </el-col>
        </el-row>

        <div style="font-size: 16px;">
          销售总业绩：{{ salePerformances }} 元
        </div>
        <el-row :gutter="10">
          <el-col :span="12" :offset="6">
            <el-table :data="tableData" style="width: 100%">
              <el-table-column type="index" label="名次" width="100">
              </el-table-column>
              <el-table-column prop="saleName" label="姓名" width="200">
              </el-table-column>
              <el-table-column prop="performance" label="业绩" width="200">
              </el-table-column>
              <el-table-column prop="groupName" label="部门"> </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { ajax } from "@/store/yg/common/utils";
export default {
  data() {
    return {
      loading: false,
      salePerformances: 0,
      tableData: [],
      salePerformanceVo: {
        channelWayMap: null,
        saleGroupMap: null
      },
      searchForm: {
        shippingWay: null,
        rangeInStockMonth: null,
        saleUserGroupId: null
      }
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    async init() {
      this.salePerformanceVo = await ajax(
        "initSalePerformanceRankingAuthorityQuery",
        {}
      );
      this.searchForm.rangeInStockMonth = [
        this.salePerformanceVo.startDate,
        this.salePerformanceVo.endDate
      ];
    },
    statistics() {
      this.countSaleProfitChart();
    },
    async countSaleProfitChart() {
      this.loading = true;
      const data = await ajax(
        "salePerformanceRankingAuthority",
        this.searchForm
      );
      if (data.code == 200) {
        this.salePerformances = data.data.totalPerformance;
        this.tableData = data.data.salePerformances;
      } else {
        this.$message.error(data.message);
      }
      this.loading = false;
    }
  }
};
</script>
<style scoped>
/deep/ .el-select {
  width: 100%;
}
</style>
